package coffeebar;

import javax.swing.*;

public class Item implements GridObject {
	private String name;
	private int id;
	private double price;
	private Icon image;
	private double discount = 1;

	public Item(int id, String name, double price, Icon image) {
		setName(name);
		setPrice(price);
		setImage(image);
		setId(id);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public String toString() {
		return name + "\t\t\t\t" + price;
	}

	public double getPrice() {
		return price * discount;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public void setImage(Icon image) {
		this.image = image;
	}

	public Icon getImage() {
		return image;
	}

	public void event() {
		Transaction t = Controller.getCurrentTransaction();
		t.add(this);
	}

	public void setDiscount(double discount) {
		this.discount = discount;
	}

	private boolean isDiscounted() {
		return (discount != 1);
			
	}
	
	public Object[] toArray() {
		Object[] l = {name, price, isDiscounted()? "discounted" : "full price"};
		return l;
	}
}
